/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.loan;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.loan.LoanMaterialtypeRe;
import com.server.modules.sys.service.loan.LoanMaterialtypeReService;

/**
 * 贷款产品资料关系表管理Controller
 * @author 王磊
 * @version 2016-09-08
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/loan/loanMaterialtypeRe")
public class LoanMaterialtypeReController extends BaseController {

	@Autowired
	private LoanMaterialtypeReService loanMaterialtypeReService;
	
	@ModelAttribute
	public LoanMaterialtypeRe get(@RequestParam(required=false) String id) {
		LoanMaterialtypeRe entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = loanMaterialtypeReService.get(id);
		}
		if (entity == null){
			entity = new LoanMaterialtypeRe();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:loan:loanMaterialtypeRe:view")
	@RequestMapping(value = {"list", ""})
	public String list(LoanMaterialtypeRe loanMaterialtypeRe, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<LoanMaterialtypeRe> page = loanMaterialtypeReService.findPage(new Page<LoanMaterialtypeRe>(request, response), loanMaterialtypeRe); 
		model.addAttribute("page", page);
		model.addAttribute("loanMaterialtypeRe", loanMaterialtypeRe);
		return "modules/sys/loan/loanMaterialtypeReList";
	}

	@RequiresPermissions("sys:loan:loanMaterialtypeRe:view")
	@RequestMapping(value = "form")
	public String form(LoanMaterialtypeRe loanMaterialtypeRe, Model model) {
		model.addAttribute("loanMaterialtypeRe", loanMaterialtypeRe);
		return "modules/sys/loan/loanMaterialtypeReForm";
	}

	@RequiresPermissions("sys:loan:loanMaterialtypeRe:edit")
	@RequestMapping(value = "save")
	public String save(LoanMaterialtypeRe loanMaterialtypeRe, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, loanMaterialtypeRe)){
			return form(loanMaterialtypeRe, model);
		}
		loanMaterialtypeReService.save(loanMaterialtypeRe);
		addMessage(redirectAttributes, "保存贷款产品资料关系成功");
		return "redirect:"+Global.getAdminPath()+"/sys/loan/loanMaterialtypeRe/?repage";
	}
	
	@RequiresPermissions("sys:loan:loanMaterialtypeRe:edit")
	@RequestMapping(value = "delete")
	public String delete(LoanMaterialtypeRe loanMaterialtypeRe, RedirectAttributes redirectAttributes) {
		loanMaterialtypeReService.delete(loanMaterialtypeRe);
		addMessage(redirectAttributes, "删除贷款产品资料关系成功");
		return "redirect:"+Global.getAdminPath()+"/sys/loan/loanMaterialtypeRe/?repage";
	}

}